<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="6">
            <a-form-model-item label="App下载地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="appurl">
              <a-input v-model="model.appurl" placeholder="请输入App下载地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="新手教程" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tutorialfile">
              <a-input v-model="model.tutorialfile" placeholder="请输入新手教程"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="首页弹窗开关" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="syswitch">
              <j-dict-select-tag type="list" v-model="model.syswitch" dictCode="yn" placeholder="请选择首页弹窗开关" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="奖励幸运币" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shareJl">
              <a-input-number v-model="model.shareJl" placeholder="请输入奖励幸运币" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="奖励优惠券ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="couponId">
              <a-input-number v-model="model.couponId" placeholder="请输入奖励优惠券ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="返佣比例" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shareFy">
              <a-input-number v-model="model.shareFy" placeholder="请输入返佣比例" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="新人首次兑换获得重抽卡ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cardId">
              <a-input-number v-model="model.cardId" placeholder="请输入新人首次兑换获得重抽卡ID" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="客服二维码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kfimage">
              <j-image-upload isMultiple  v-model="model.kfimage" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="小程序ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mpappid">
              <a-input v-model="model.mpappid" placeholder="请输入小程序ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="小程序密钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mpappkey">
              <a-input v-model="model.mpappkey" placeholder="请输入小程序密钥"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="微信支付商户号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payid">
              <a-input-number v-model="model.payid" placeholder="请输入微信支付商户号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="微信支付密钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paykey">
              <a-input v-model="model.paykey" placeholder="请输入微信支付密钥"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="连抽优惠比例" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lcyhbl">
              <a-input-number v-model="model.lcyhbl" placeholder="请输入连抽优惠比例" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="快递100key" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kdkey">
              <a-input v-model="model.kdkey" placeholder="请输入快递100key"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="快递100customer" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kdcustomer">
              <a-input v-model="model.kdcustomer" placeholder="请输入快递100customer"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="阿里云id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accessid">
              <a-input v-model="model.accessid" placeholder="请输入阿里云id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="阿里云key" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accesskey">
              <a-input v-model="model.accesskey" placeholder="请输入阿里云key"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="OSS实例地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endpoint">
              <a-input v-model="model.endpoint" placeholder="请输入OSS实例地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="OSS存储空间名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bucket">
              <a-input v-model="model.bucket" placeholder="请输入OSS存储空间名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="APP支付宝支付ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="appid">
              <a-input v-model="model.appid" placeholder="请输入APP支付宝支付ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="APP支付应用私钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rsaprivatekey">
              <a-textarea v-model="model.rsaprivatekey" rows="4" placeholder="请输入APP支付应用私钥" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="APP支付应用公钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="alipayrsapublickey">
              <a-textarea v-model="model.alipayrsapublickey" rows="4" placeholder="请输入APP支付应用公钥" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="APP微信登录ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wxappid">
              <a-input v-model="model.wxappid" placeholder="请输入APP微信登录ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="App微信登录key" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wxappkey">
              <a-input v-model="model.wxappkey" placeholder="请输入App微信登录key"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="易支付ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yzfid">
              <a-input v-model="model.yzfid" placeholder="请输入易支付ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="易支付密钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yzfkey">
              <a-input v-model="model.yzfkey" placeholder="请输入易支付密钥"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="易支付地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yzfurl">
              <a-input v-model="model.yzfurl" placeholder="请输入易支付地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="boxflId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="boxflId">
              <a-input-number v-model="model.boxflId" placeholder="请输入boxflId" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="domain" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="domain">
              <a-input v-model="model.domain" placeholder="请输入domain"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="一级会员返佣比例" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="first">
              <a-input-number v-model="model.first" placeholder="请输入一级会员返佣比例" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="二级会员返佣比例" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="second">
              <a-input-number v-model="model.second" placeholder="请输入二级会员返佣比例" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'BoxSettingForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           yzfid: [
              { required: true, message: '请输入易支付ID!'},
           ],
           yzfkey: [
              { required: true, message: '请输入易支付密钥!'},
           ],
           yzfurl: [
              { required: true, message: '请输入易支付地址!'},
           ],
           boxflId: [
              { required: true, message: '请输入boxflId!'},
           ],
           domain: [
              { required: true, message: '请输入domain!'},
           ],
           first: [
              { required: true, message: '请输入一级会员返佣比例!'},
           ],
           second: [
              { required: true, message: '请输入二级会员返佣比例!'},
           ],
        },
        url: {
          add: "/setting/boxSetting/add",
          edit: "/setting/boxSetting/edit",
          queryById: "/setting/boxSetting/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>